/*
 * DataTables Date Sorting
 * From: http://www.datatables.net/plug-ins/sorting
 * Modified by: Håvard Lindset
 */
function trim(str) {
    str = str.replace(/^\s+/, '');
    for (var i = str.length - 1; i >= 0; i--) {
        if (/\S/.test(str.charAt(i))) {
            str = str.substring(0, i + 1);
            break;
        }
    }
    return str;
}

function getDateTimeValue(str) {
    if (trim(str) != '') {
        var frDatea = trim(str).split(' ');
        var frTimea = frDatea[1].split(':');
        var frDatea2 = frDatea[0].split('.');
        var x = (frDatea2[2] + frDatea2[1] + frDatea2[0] + frTimea[0] + frTimea[1]) * 1;
    } else {
        var x = 10000000000000; // = l'an 1000 ...
    }
    return x;
}

jQuery.fn.dataTableExt.oSort['date-euro-asc'] = function(a, b) {
    if (a == "") return -1;
    if (b == "") return 1;

    var x = getDateTimeValue(a);
    var y = getDateTimeValue(b);
    var z = ((x < y) ? -1 : ((x > y) ? 1 : 0));
    return z;
};

jQuery.fn.dataTableExt.oSort['date-euro-desc'] = function(a, b) {
    if (a == "") return 1;
    if (b == "") return -1;
    
    var x = getDateTimeValue(a);
    var y = getDateTimeValue(b);
    var z = ((x < y) ? 1 : ((x > y) ? -1 : 0));                 
    return z;
};
